package com.hl.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.entity.SysQuestion;
import com.hl.sfzy.mapper.SysQuestionMapper;
import com.hl.sfzy.mapper.SysReplyMapper;
import com.hl.sfzy.service.SysQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ffc
 * @version 1.0
 * @description: TODO
 * @className: SysQuestionServiceImpl
 * @date 2024/7/12 11:35
 */

@Service("sysQuestionService")
public class SysQuestionServiceImpl implements SysQuestionService {

    @Autowired
    SysQuestionMapper sysQuestionMapper;
    @Autowired
    SysReplyMapper sysReplyMapper;

    @Override
    public int add(SysQuestion entity) {
        return sysQuestionMapper.insert(entity);
    }

    @Override
    public int edit(SysQuestion entity) {
        return 0;
    }

    @Override
    public int remove(Integer id) {
        return sysQuestionMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return sysQuestionMapper.deleteBatch(ids);
    }

    @Override
    public List<SysQuestion> find(SysQuestion entity) {
        return sysQuestionMapper.select(entity);
    }

    @Override
    public SysQuestion findById(Integer id) {
        return sysQuestionMapper.selectById(id);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, SysQuestion entity) {
        PageHelper.startPage(pageNum,pageSize);
        List<SysQuestion> list = sysQuestionMapper.select(entity);
        PageInfo<SysQuestion> pageInfo = new PageInfo<>(list);
        Map<String,Object> map = new HashMap<>();
        map.put(CommonConstant.PAGE_LIST,list);
        map.put(CommonConstant.TOTAL,pageInfo.getTotal());
        map.put(CommonConstant.PAGE_TOTAL,pageInfo.getPages());
        return map;
    }

    @Override
    public Map<String,Object> findOrder(Integer pageNum, Integer pageSize,Integer order) {
        PageHelper.startPage(pageNum,pageSize);
        System.out.println(pageNum+""+pageSize);
        System.out.println(pageNum+""+pageSize);
        List<SysQuestion> list = sysQuestionMapper.selectOrder(order);
        PageInfo<SysQuestion> pageInfo = new PageInfo<>(list);
        Map<String,Object> hashMap = new HashMap<>();
        hashMap.put(CommonConstant.PAGE_LIST,list);
        hashMap.put(CommonConstant.TOTAL,pageInfo.getTotal());
        hashMap.put(CommonConstant.PAGE_TOTAL,pageInfo.getPages());
        return hashMap;
    }
}
